package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmCustomerhis;
import com.ruoyi.crm.service.ICrmCustomerhisService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息历史Controller
 * 
 * @author ruoyi
 * @date 2024-01-03
 */
@RestController
    @RequestMapping("/crm/customerhis")
    public class CrmCustomerhisController extends BaseController
    {
        @Autowired
        private ICrmCustomerhisService crmCustomerhisService;

    /**
     * 查询客户信息历史列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerhis:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerhis crmCustomerhis)
    {
        startPage();
        List<CrmCustomerhis> list = crmCustomerhisService.selectCrmCustomerhisList(crmCustomerhis);
        return getDataTable(list);
    }

    /**
     * 导出客户信息历史列表
     */
    @PreAuthorize("@ss.hasPermi('crm:customerhis:export')")
    @Log(title = "客户信息历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCustomerhis crmCustomerhis)
    {
        List<CrmCustomerhis> list = crmCustomerhisService.selectCrmCustomerhisList(crmCustomerhis);
        ExcelUtil<CrmCustomerhis> util = new ExcelUtil<CrmCustomerhis>(CrmCustomerhis.class);
        util.exportExcel(response, list, "客户信息历史数据");
    }

    /**
     * 获取客户信息历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:customerhis:query')")
    @GetMapping(value = "/{crmCustomerhisId}")
    public AjaxResult getInfo(@PathVariable("crmCustomerhisId") Long crmCustomerhisId)
    {
        CrmCustomerhis crmCustomerhis = crmCustomerhisService.selectCrmCustomerhisByCrmCustomerhisId(crmCustomerhisId);
        return success(crmCustomerhisService.selectCrmCustomerhisByCrmCustomerhisId(crmCustomerhisId));
    }

    /**
     * 新增客户信息历史
     */
    @PreAuthorize("@ss.hasPermi('crm:customerhis:add')")
    @Log(title = "客户信息历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerhis crmCustomerhis)
    {
        return toAjax(crmCustomerhisService.insertCrmCustomerhis(crmCustomerhis));
    }

    /**
     * 修改客户信息历史
     */
    @PreAuthorize("@ss.hasPermi('crm:customerhis:edit')")
    @Log(title = "客户信息历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerhis crmCustomerhis)
    {
        return toAjax(crmCustomerhisService.updateCrmCustomerhis(crmCustomerhis));
    }

    /**
     * 删除客户信息历史
     */
    @PreAuthorize("@ss.hasPermi('crm:customerhis:remove')")
    @Log(title = "客户信息历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{crmCustomerhisIds}")
    public AjaxResult remove(@PathVariable Long[] crmCustomerhisIds)
    {
        return toAjax(crmCustomerhisService.deleteCrmCustomerhisByCrmCustomerhisIds(crmCustomerhisIds));
    }
}
